// import router from "@/router"
import axios from "axios"

axios.interceptors.request.use((config)=>{
    const token = localStorage.getItem("token")
    config.headers.Authorization = `Bearer ${token}`

    return config
},(err)=>{
    return Promise.reject(err)
})

axios.interceptors.response.use((response)=>{
    const {authorization} = response.headers
    authorization&&localStorage.setItem("token",authorization)
    return response
},(err)=>{
    const {status} = err.response
    if(status==401){
        window.location.href = "#/login"
        // ElMessage.error("token过期，请重新登录")
        return
    }
    return Promise.reject(err)
})
